const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const mysql = require('./db')
const app = express();

const MyGraphQLSchema = require('./schema/default');
const cors = require('cors');

app.use(cors());

app.use(express.json());//express.json=bodyParser.json
app.use(express.urlencoded({ extended: true }));

// 配置express中间件
app.use('/graphql', graphqlHTTP({
    schema: MyGraphQLSchema, // MyGraphQLSchema待定
    graphiql: true, // 开发环境打开调试面板，生产的时候可以关闭
  }),
);

app.get('/', async (req, res) => {
    const result = await mysql.query('select * from account');
    res.json({
      code: 0,data: result,
    })
})

module.exports = app;
